
package flc.ast.dialog;

import android.content.Context;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.lxj.xpopup.core.AttachPopupView;

import java.util.ArrayList;
import java.util.List;

import flc.ast.R;
import flc.ast.adapter.ScaleAdapter;
import flc.ast.bean.MyScaleBean;

public class ScaleDialog extends AttachPopupView implements View.OnClickListener {

    private RecyclerView recyclerView;
    private ScaleAdapter scaleAdapter;

    public ScaleDialog(@NonNull Context context) {
        super(context);
    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_scale_style;
    }

    @Override
    protected void onCreate() {
        super.onCreate();
        initView();
    }

    protected void initView() {
        recyclerView = findViewById(R.id.rvScaleList);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
        scaleAdapter = new ScaleAdapter();
        recyclerView.setAdapter(scaleAdapter);
        scaleAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                if (listener != null) {
                    dismiss();
                    listener.click(scaleAdapter.getItem(position));
                }
            }
        });
        List<MyScaleBean> list = new ArrayList<>();
        list.add(new MyScaleBean(R.drawable.yt, "H,W"));
        list.add(new MyScaleBean(R.drawable.yiyi, "1:1"));
//        list.add(new MyScaleBean(R.drawable.sans, "3:4"));
        list.add(new MyScaleBean(R.drawable.sis, "4:3"));
        list.add(new MyScaleBean(R.drawable.lj2, "16:9"));
        scaleAdapter.setList(list);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            default:
                break;
        }
    }

    private Ilistener listener;

    public void setListener(Ilistener listener) {
        this.listener = listener;
    }

    public interface Ilistener {
        void click(MyScaleBean scaleBean);
    }

}
